﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using chatc_application.connect;
using chatc_application.frame;


namespace chatc_application
{
    public partial class FormLogin : Form
    {
        private ConnectRemote con;
        private ClientChat cc;
        public FormLogin(ConnectRemote con, ClientChat cc)
        {
            InitializeComponent();
            this.con = con;
            this.cc = cc;
        }
    

        private void buttonNewUser_Click(object sender, EventArgs e)
        {
            Boolean result = con.addNewUser(textBoxUserName.Text.ToString(), textBoxPasswared.Text.ToString());
            if (result)
            {
                labelinfo.Text = "User is created";
            }
            else
            {
                labelinfo.Text = "Username exists, user not created"; 
            }


            
        }

        private void FormLogin_Load(object sender, EventArgs e)
        {

        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            String username = textBoxUserName.Text.ToString();
            if (con.logon(username, textBoxPasswared.Text.ToString(), cc))
            {
                labelinfo.Text = "Login in...";
                cc.setUsername(username);
                this.Dispose();
                
                
            }
            else
            {
                labelinfo.Text = "Sorry wrong username password combo";
            }


        }


        

        

        
    }

        
}
